<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>逾期催收列表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同编号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd"  type="text" ltype="combobox">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">逾期天数</div>
                    <div class="field">
                        <input ligerui="width: 82" name="ovdDaysMin" id="ovdDaysMin" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                        -
                        <input ligerui="width: 82" name="ovdDaysMax" id="ovdDaysMax" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">应收日期</div>
                    <div class="field">
                        <input ligerui="width: 82" name="ovdDtMin" id="ovdDtMin" type="text" class="ui-datepicker"
                               value="">
                        -
                        <input ligerui="width: 82" name="ovdDtMax" id="ovdDtMax" type="text" class="ui-datepicker"
                               value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">分配状态</div>
                    <div class="field">
                        <input name="allocationFlag" id="allocationFlag" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">是否资管业务</div>
                    <div class="field">
                        <select name="bizFlag" id="bizFlag">
                            <option value="2">全部</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">是否小贷业务</div>
                    <div class="field">
                        <select name="mcrCd" id="mcrCd">
                            <option value="2">全部</option>
                            <option value="1">内部</option>
                            <option value="0">外部</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">第三方机构</div>
                    <div class="field">
                        <input name="insCode" id="insCode" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">最高逾期期次</div>
                    <div class="field">
                        <input name="maxPd" id="maxPd" type="text" class="ui-textbox" value="" validate="{digits:true,min:1,max:100}">
                    </div>
                </div>
                <div class="fieldBox" id="tableSearchBox">
                    <div class="label">贷款业务类型</div>
                    <div class="field">
                        <select name="tableNm" id="tableNm">
                            <option value="">请选择</option>
                            <option value="MCR_BILL_M">小贷业务</option>
                            <option value="PBL_BILL_M">垫款业务</option>
                            <option value="OTHERS">租赁业务</option>
                        </select>
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                   <%-- <span id="assignTaskBtn" class="sq-button sq-button-round">分配</span>--%>
                    <span id="collectTaskBtn" class="sq-button sq-button-round">领取</span>
                    <sys:funcAuth resCd="MovdNExportBtn">
                       <span id="exportXlsxBtn" class="sq-button sq-button-round">导出</span>
                    </sys:funcAuth>
                </div>
                <div class="clearFix"></div>

            </div>
        </form>
    </div>

    <div class="sqPanel" style="margin-bottom: 0;">
        <div class="sqPanel_head">
            <table class="table_full">
                <tr>
                    <td><b>应收总金额合计(元): </b><span id="arAmt"/></td>
                    <td><b>逾期金额合计(元): </b><span id="ovdAmt"/></td>
                    <td><b>罚息金额合计(元): </b><span id="fineAmt"/></td>
                </tr>
            </table>
        </div>
        <div class="sqPanel_body">
            <div id="ligergrid1" class="sq-grid"></div>
        </div>
    </div>

</div>

<script type="text/javascript">
    var grid = null, form = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/risk/overdueCollect/initGroupTask.do',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 200, align: 'left', enabledSort: false},
               /*  {display: '逾期合同数', name: 'ovdCntQty', width: 100, align: 'right', enabledSort: false},
                {display: '逾期支付表数', name: 'ovdPayQty', width: 100, align: 'right', enabledSort: false}, */
                {display: '逾期天数', name: 'ovdDays', width: 100, align: 'right', enabledSort: false},
                {display: '最高逾期期次', name: 'maxPd', width: 100, align: 'right', enabledSort: false},
                {
                    display: '应收金额(元)', name: 'arAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '<a style="cursor: pointer;" onclick="calcInterest(' + index + ');">&yen;' + FormatMoney(rowdata.arAmt / 100) + '</a> ';
                    }
                },
                {
                    display: '逾期金额(元)', name: 'ovdAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdAmt / 100);
                    }
                },
                {
                    display: '罚息金额(元)', name: 'fineAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fineAmt / 100);
                    }
                },
                {display: '任务人', name: 'usrNm', width: 80, align: 'center', enabledSort: false},
               /*  {
                    display: '操作', width: 250, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="repaymentDtl(' + rowdata.cstId + ',\'' + rowdata.cstNm + '\');"><i class="sqBtnIco_49"></i>还款明细</a>  ' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="overdueDtl(' + rowdata.cstId + ');"><i class="sqBtnIco_50"></i>逾期明细</a> ' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="qyCommRec(' + rowdata.cstId + ',\'' + rowdata.cstNm + '\');"><i class="sqBtnIco_51"></i>催收记录</a>';
                    }
                }, */
            ],
            pageSize: 50,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            rownumbers: true,  //显示序号
            checkbox: true,
            allowUnSelectRow: true,
            alternatingRow: true,
        });
        grid.setHeight(100);

        //事业部
        $("#buOrgCd").ligerComboBox({isShowCheckBox: true, isMultiSelect: true,
                data: ${buOrgCdList},
                valueField: 'key',
                textField:'value',
        });
        $("#insCode").ligerComboBox({isShowCheckBox: true, isMultiSelect: true,
            data: ${insList},
            valueField: 'key',
            textField:'value',
        });
        //是否已分配
        $("#allocationFlag").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });

        form = $("#searchBar").ligerForm();
 //        liger.get("buOrgCd").setData(${buOrgCdList});
        liger.get("allocationFlag").setData([{"key":"0","value":"未分配"},{"key":"1","value":"已分配"}]);

        getOvdAmtSummary();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
            getOvdAmtSummary();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });
        
      //导出
        $("#exportXlsxBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                url: '<%=path%>/risk/ovdCollect/exportOverdueInfoList.do?queryType=${queryType}',
                data:data,
                beforeSend:function(){
                    wait_dialog=$.ligerDialog.SQalert({content: '正在导出...',SQ_type: "waitting"});
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        window.open(msg.data);
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        }); 

        //导出PDF
        $("#exportPdfBtn").click(function (event) {
            exportOverDue("pdf");
        });
        //导出Excel
        $("#exportXlsBtn").click(function (event) {
            exportOverDue("xls");
        });

        //分配催收任务
        $("#assignTaskBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].cstId);
            }

            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            $.ligerDialog.SQopen({
                width: 650,
                height: 500,
                title: '分配任务',
                url: '<%=path%>/risk/rskUsrCstR/toListPage.do',
                buttons: [
                    {
                        text: "关闭", onclick: onCancel, type: 'cancel'
                    }
                ],
                data: {ids: _ids},
            });

        });

        //领取催收任务
        $("#collectTaskBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].cstId);
            }

            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids)},
                url: '<%=path%>/risknew/rskUsrCstR/collectTask.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });

    });

    //查询汇总
    function getOvdAmtSummary() {
        var data = form.getData();
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: data,
            url: '<%=path%>/risk/overdueCollect/sum.do',
            success: function (msg) {
                    $("#arAmt").text(FormatMoney(msg.arAmt / 100));
                    $("#ovdAmt").text(FormatMoney(msg.ovdAmt / 100));
                    $("#fineAmt").text(FormatMoney(msg.fineAmt / 100));
            }
        });
    }

    /* 还款明细 */
    function repaymentDtl(cstId, cstNm) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '还款明细',
            url: '<%=path%>/capital/capOverdueInfo/toRepaymentDtl.do?cstId=' + cstId + "&cstNm=" + cstNm,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    /* 逾期明细 */
    function overdueDtl(cstId) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '逾期明细',
            url: '<%=path%>/capital/capOverdueInfo/toOverdueDtl.do?cstId=' + cstId,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    //查询催收记录
    function qyCommRec(_cstId, _cstNm) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 1100,
            height: 500,
            title: '催收记录',
            url: '<%=path%>/risk/rskCommRec/toListPage.do?cstId=' + _cstId + '&cstNm=' + _cstNm + '&qt=2',
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    //结算罚息
    function calcInterest(rowId) {
        var rowdata = grid.getRow(rowId);
        var req = "?cstId=" + rowdata.cstId + "&ovdDays=" + rowdata.ovdDays + "&fineAmt=" + rowdata.fineAmt + "&recAmt=" + rowdata.arAmt;
        $.ligerDialog.open({
            width: 450,
            height: 280,
            title: '应付金额计算',
            url: '<%=path%>/risk/ovdCollect/toCalcAmtPage.do' + req,

        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
</script>

</body>
</html>
